import datetime
from django.db import models

from django.utils import timezone

# Create your models here.

class Result(models.Model):
    game_id = models.CharField(max_length=16)
    issue_id = models.CharField(max_length=32)

    date = models.DateField()

    open_code = models.CharField(max_length=16)

    @property
    def _sum(self):
        return sum(map(int, self.open_code.split(',')))

    @property
    def singular(self):
        return self._sum & 1

    @property
    def large(self):
        if self.game_id == 'HF_FFK3':
            return int(self._sum > 10)

    class Meta:
        index_together = [
            ('game_id', 'date'),
        ]
        unique_together = [
            ('game_id', 'issue_id'),
        ]
    
    class DataFetcher:
        def __init__(self, game_id):
            self.game_id = game_id

        def today(self):
            return Result.objects.filter(
                date=timezone.localdate()
            ).order_by(
                '-issue_id'
            )
        
    ffk3 = DataFetcher('HF_FFK3')